<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace App\Setting;

use App\Base\BaseForm;
use App\Base\ViewsInList;
use App\Model\ArtCategoryModel;
use App\Model\LazyCommon\CCM;

class ArtCategorySetting{

    /*手动获取的配置项*/
    public $entityCnName = "资讯";//模块名称
    //public $table = "ArtCategory";//数据表名称
    public $table = "Art_Category";//数据表名称
    public $editKeys = array('id','name','level','orders','parent','pic','link','is_Index');//后台管理列表中可以直接编辑的字段
    public $perPage = 1000;//后台管理列表中可以直接编辑的字段
    public $noDelete = [];

    /*自动获取的配置项*/
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $entity;
    public $modelPath;
    public $doctrine;
    public $em;

    public function __construct($doctrine)
    {
        $this->bundleName = "App";
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        //$this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",__CLASS__));
        $this->entityPath = "App\\Entity\\".$this->entityName;
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->doctrine = $doctrine;
        $this->em = $doctrine->getManager();
    }

    public function listConfig()
    {
        $default = array();
        $default["Art_Category AS ArtCategory"]["select"] = array('id','name','level','is_Index','orders','parent','pic','link');
        $default["Art_Category AS ArtCategory"]["search"] = array('id','name','level','is_Index','orders','parent','pic','link');
        $default["Art_Category AS ArtCategory"]["condition"] = array('id','name','level','is_Index','orders','parent','pic','link');
        $default["Art_Category AS ArtCategory"]["orderBy"] = array('id','name','level','is_Index','orders','parent','pic','link');

        $join = array();
//        $join["ArtCategoryCategory"]["on"] = "";
//        $join["ArtCategoryCategory"]["select"] = array();
//        $join["ArtCategoryCategory"]["search"] = array();
//        $join["ArtCategoryCategory"]["condition"] = array();
//        $join["ArtCategoryCategory"]["orderBy"] = array();

        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function viewConfig()
    {

    }


    public function formConfig()
    {
        $BaseForm = new BaseForm();

        $ArtCategoryModel = new ArtCategoryModel($this->doctrine);
        $CCM = new CCM($this->doctrine);
        $parentData = $ArtCategoryModel->getAllArtCategoryTree();

        $parentData = $CCM->createSelectFromCategoryTree($parentData);
//        var_dump($parentData);
//        $parentData = array_flip($parentData);
//        array_unshift($parentData,"根目录");
//        $parentData = array_flip($parentData);
        $config["parent"] = $BaseForm->select("parent","上级",($parentData));

        $config["name"] = $BaseForm->text("name","名称");
//        $config["level"] = $BaseForm->text("level","等级");
        $config["orders"] = $BaseForm->text("orders","排序");
//        $config["pic"] = $BaseForm->pic("pic","图片");
        $config["link"] = $BaseForm->text("link","编码");
        return $config;
    }
}
